/**
 * Description
 *
 * Creation Date 26/12/2017
 * @author Candy
 */
import Immutable from 'immutable'
import { combineReducers } from 'redux';
import * as types from './../actionTypes';

const defaultState = Immutable.fromJS({ data: {}, isFetching: false });
//首次渲染时获取数据
const initDataReducer = (state = defaultState, action = {}) => {
	switch (action.type) {
		case types.REQUEST_DATA:
			return state.set('isFetching', true);
		case types.RECEIVE_DATA:
			return Immutable.Map({'data': action.data});
		default:
			return state;
	}
};
//手动获取数据
const fetchDataReducer = (state= defaultState, action={}) => {
	switch (action.type) {
		case types.GET_DATA_START:
			return state.set('isFetching', true);
		case types.GET_DATA_SUCCESS:
			return Immutable.Map({'data': action.data});
		default:
			return state;
	}
}

export default combineReducers({
	initDataReducer,
	fetchDataReducer
})